﻿using FirstTry.CTR;
using FirstTry.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Transactions;

namespace FirstTry
{
    
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in both code and config file together.
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Single)] 
    
    public class Service1 : IService1
    {

        BatteryCtr bctr = new BatteryCtr();
        LocationCtr lctr = new LocationCtr();
        UserCtr uctr = new UserCtr();
        ReservationCtr rctr = new ReservationCtr();
        LeasedCtr lectr = new LeasedCtr();
       

        public string getBatteryLocation(string ID)
        {
            Battery b = new Battery();
            b = bctr.getBattery(ID);
            String a = b.location.getLocation();

            return a;
        }

        public string getLocationName(string ID)
        {
            Location l = new Location();
            l = lctr.getCityByID(ID);

            return l.getCity();
        }
        public Location getLocation(String ID)
        {
            return lctr.getCityByID(ID);

        }

        [OperationBehavior(TransactionScopeRequired = true, TransactionAutoComplete = true)]
        public void makeReservation(int y, int x, string userID)
        {
            User u = uctr.getUser(userID);
            Location l = lctr.getLocationByCoordinates(y,x);

            rctr.makeReservation(l, u);
        }

        public List<Location> getAllLocation()
        {
            return lctr.getLocation();
        }

        public List<User> getAllUsers()
        {
            return uctr.getUsers();
        }

        public List<Battery> getAllBattery()
        {
            return bctr.getAllBattery();
        }

        public List<Reservation> getAllReservation()
        {
            return rctr.getAllReservation();
        }

        public List<Leased> getAllLeased()
        {
            return lectr.getLeased();
        }

        public List<Battery> getBatteryByLocation(string locationID)
        {
            List<Battery> bl = bctr.getBatteryByLocation(locationID);
            return bl;
        }

        public bool checkBatteryByLocation(int y, int x)
        {
            return bctr.checkBatteryByLocation(y, x);
        }

        
    }
}
